import { GlobalShortcutContext } from '../mconfig';
import { GlobalShortcutMenu, globalShortcutReducers } from '../common';

import '../common/shortcutStyles.less';
import { GlbalShortcutBtn } from './GlbalShortcutBtn';
import { ShortcutUpdateDrawer } from './ShortcutUpdateDrawer';
import { ShortcutContactDrawer } from './ShortcutContactDrawer';
import { connect } from 'umi';
import { GlobalShortcutKeyAPI } from '../common/type';
import { reloadUserInfoService } from '../services';

const GlobalShortcutKey: React.FC<GlobalShortcutKeyAPI.IGlbalShortcutKey> = ({
  dispatch,
  userInfoObj,
  curRes,
}) => {
  /**
   * 根类名
   */
  const prefixCls = 'global-shortcutkey-';

  /**
   * 快捷键 reducer
   */
  const { shortcutCheckKey, shortcutDispatch, mailOrPhoneSuccess } =
    globalShortcutReducers();

  /**
   * 获取数据详情
   */
  const { reloadUserInfoRun } = reloadUserInfoService(dispatch);

  return (
    <GlobalShortcutContext.Provider
      value={{
        userInfoObj,
        prefixCls,
        curRes,
        shortcutCheckKey,
        shortcutDispatch,
        mailOrPhoneSuccess,
        reloadUserInfoRun,
      }}
    >
      <GlobalShortcutMenu>
        {/* 按钮 */}
        <GlbalShortcutBtn />
      </GlobalShortcutMenu>

      <ShortcutUpdateDrawer />

      <ShortcutContactDrawer />
    </GlobalShortcutContext.Provider>
  );
};

export default connect(({ baseLogin, navTab }: Record<string, any>) => ({
  permissions: baseLogin?.permissions,
  navTab,
}))(GlobalShortcutKey);
